const http = require('http')
const fs = require('fs')
const path = require('path')
const server2Port = 3001
http
  .createServer((req, res) => {
    console.log(req.url, '请求参数')
    // res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000')
    const url = req.url.replace(/^\/api/, '')

    if (url === '/') {
      res.end(String(666))
    }
    if (url.includes('/username')) {
      res.writeHead('200', {
        'Content-Type': 'text/javascript;charset=utf-8',
      })
      console.log(url, '---')
      const data = fs.readFileSync('./jsonp/name.js', 'utf-8')
      res.end(data)
    }
  })
  .listen(server2Port, () => {
    console.log('server2 启动在', server2Port, '端口')
  })
